package com.example.sunflowers.data.db

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow

/**
 *
 * @Author： LJH
 * @Time： 2024/1/26
 * @description：
 */
@Dao
interface PlantDao {

    @Query("SELECT * FROM plants ORDER BY name")
    fun getPlants(): Flow<List<Plant>>

    @Query("SELECT * FROM plants WHERE growZoneNumber = :growZoneNumber ORDER BY name")
    fun getPlantsWithGrowZoneNumber(growZoneNumber:Int):Flow<List<Plant>>

    @Query("SELECT * FROM plants WHERE id = :plantId")
    fun getPlant(plantId:String):Flow<Plant>

    @Query("SELECT * FROM plants WHERE id = :plantId")
    fun getPlantById(plantId:String):Plant

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAll(plants:List<Plant>)
}